package kkb.IOTest;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

//异常日志  打印
public class ExceptionStreamTest {

    public static void main(String[] args) throws FileNotFoundException {

        try{
            String a = null;
            a.toString();
        }catch (Exception e){
            // 打印字符流   输出流
            PrintWriter printWriter = new PrintWriter("D://lookbug.txt");
            //时间格式
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            //获取当前时间 放入流
            printWriter.println(simpleDateFormat.format(new Date()));
            //把异常打印到 输出流对应的文件
            e.printStackTrace(printWriter);
            //关流
            printWriter.close();
        }
    }
}
